package com.yiyahui.project.erp.service.impl;

import java.util.List;
import com.yiyahui.common.utils.DateUtils;
import com.yiyahui.project.erp.domain.YiyaMarketReservation;
import com.yiyahui.project.erp.service.IYiyaMarketReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yiyahui.project.erp.mapper.YiyaChannelAuditMapper;
import com.yiyahui.project.erp.domain.YiyaChannelAudit;
import com.yiyahui.project.erp.service.IYiyaChannelAuditService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 渠道修改审核Service业务层处理
 * 
 * @author yiyahui
 * @date 2020-05-27
 */
@Service
public class YiyaChannelAuditServiceImpl implements IYiyaChannelAuditService 
{
    @Autowired
    private YiyaChannelAuditMapper yiyaChannelAuditMapper;

    @Autowired
    private IYiyaMarketReservationService yiyaMarketReservationService;

    /**
     * 查询渠道修改审核
     * 
     * @param id 渠道修改审核ID
     * @return 渠道修改审核
     */
    @Override
    public YiyaChannelAudit selectYiyaChannelAuditById(Long id)
    {
        return yiyaChannelAuditMapper.selectYiyaChannelAuditById(id);
    }

    /**
     * 查询渠道修改审核列表
     * 
     * @param yiyaChannelAudit 渠道修改审核
     * @return 渠道修改审核
     */
    @Override
    public List<YiyaChannelAudit> selectYiyaChannelAuditList(YiyaChannelAudit yiyaChannelAudit)
    {
        return yiyaChannelAuditMapper.selectYiyaChannelAuditList(yiyaChannelAudit);
    }

    /**
     * 新增渠道修改审核
     * 
     * @param yiyaChannelAudit 渠道修改审核
     * @return 结果
     */
    @Override
    public int insertYiyaChannelAudit(YiyaChannelAudit yiyaChannelAudit)
    {
        yiyaChannelAudit.setCreateTime(DateUtils.getNowDate());
        return yiyaChannelAuditMapper.insertYiyaChannelAudit(yiyaChannelAudit);
    }

    /**
     * 修改渠道修改审核
     * 
     * @param yiyaChannelAudit 渠道修改审核
     * @return 结果
     */
    @Transactional(rollbackFor=Exception.class)
    public int updateYiyaChannelAudit(YiyaChannelAudit yiyaChannelAudit)
    {
        yiyaChannelAudit.setUpdateTime(DateUtils.getNowDate());
        int i = yiyaChannelAuditMapper.updateYiyaChannelAudit(yiyaChannelAudit);
        YiyaMarketReservation yiyaMarketReservationRequest = new YiyaMarketReservation();
        yiyaMarketReservationRequest.setId(yiyaChannelAudit.getMarketReservationId() != null && yiyaChannelAudit.getAuditStatus() == 1 ? yiyaChannelAudit.getMarketReservationId() : 0);
        yiyaMarketReservationRequest.setChannelFirst(yiyaChannelAudit.getChannelFirst());
        yiyaMarketReservationRequest.setChannelSecond(yiyaChannelAudit.getChannelSecond());
        yiyaMarketReservationRequest.setChannelThird(yiyaChannelAudit.getChannelThird());
        yiyaMarketReservationRequest.setMediumFirst(yiyaChannelAudit.getMediumFirst());
        yiyaMarketReservationRequest.setMediumSecond(yiyaChannelAudit.getMediumSecond());
        yiyaMarketReservationRequest.setMediumThird(yiyaChannelAudit.getMediumThird());
        yiyaMarketReservationRequest.setAffiliationPerson(yiyaChannelAudit.getNewAffiliationPerson());
        yiyaMarketReservationRequest.setFilingPerson(yiyaChannelAudit.getNewFilingPerson());
        yiyaMarketReservationRequest.setFollowPerson(yiyaChannelAudit.getNewFollowPerson());
        yiyaMarketReservationService.updateYiyaMarketReservation(yiyaMarketReservationRequest);
        return i;
    }

    /**
     * 批量删除渠道修改审核
     * 
     * @param ids 需要删除的渠道修改审核ID
     * @return 结果
     */
    @Override
    public int deleteYiyaChannelAuditByIds(Long[] ids)
    {
        return yiyaChannelAuditMapper.deleteYiyaChannelAuditByIds(ids);
    }

    /**
     * 删除渠道修改审核信息
     * 
     * @param id 渠道修改审核ID
     * @return 结果
     */
    @Override
    public int deleteYiyaChannelAuditById(Long id)
    {
        return yiyaChannelAuditMapper.deleteYiyaChannelAuditById(id);
    }
}
